<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@taglib uri="/thor-toolkit" prefix="tt" %>
<!DOCTYPE html>
<html>
<head>
	<tt:env/>
    <title>对标管理平台</title>
    <meta charset="utf-8">
    <%@include file="../common-include.jspf"%>
    <style>
        .left-div{
            background-color:#C8C9CB;
            text-align:center;
        }

        .left-div-title{
            font-size:20px;
        }
        .link1{
            color:#555;
            cursor:pointer;
            text-decoration: underline;
        }
        .link1:hover{
            color:#007ded;
        }
        .tui-grid-line .link1{
            color:#555;
        }
        .tui-grid .tui-grid-line-selected .tui-grid-cell .tui-grid-cell-content .link1{
            color:#555;
        }
        .tui-grid-line-selected .tui-grid-cell .tui-grid-cell-content .link1{
            color:#fff;
        }
        .select-input{
        	width:300px;
        }
    </style>
    <script>
    	var grid;
        $(function(){
            tui.ctrl.button("benchmarkManage").checked(true);
            grid = tui.ctrl.grid("valueGrid");
            grid.columns([
                             { name: '机构', key: 'DeptName' },
                             { name: '指标', key: 'FiledName' },
                             { name: '年份', key: 'ReportYear' },
                             { name: '年度最优业务值', key: 'svalue' },
                             { name: '标杆值', key: 'BenchmarkValue' },
                             { name: '单位', key: 'FieldUnit' },
                             { name: '最后编辑人', key: 'lastEditUser'},
                             { name: '备注', key: 'Remark'},
                             {name: '最后编辑时间', key: 'lastEditTime',format:function(data){
                            	 if(data.rowIndex<0){return;}
                            	 data.cell.firstChild.innerHTML ="" ;
                            	 if(data.value)
                            	 	data.cell.firstChild.innerHTML =data.value.substr(0,10);
                             }}
                           ]);
          
          //query comments
            queryForm=tui.ctrl.form("queryValueForm");
            
            tui.ctrl.button("runBtn").on("click",function(data){
            	queryForm.submit();
            });
            
            queryForm.on("receive", function(data){
           		tui.ctrl.paginator("pageBtn").totalSize(data.length);
           		grid.data(data);
           	});
            
            var yearInput=tui.ctrl.input("yearSelect");
            var yearData=[];
            var myDate = new Date();
            var year=myDate.getFullYear();
            for(var i=0;i<=(year-2014);i++){
            	yearData.push({key:year-i,value:(year-i)+"年"});
            }
            yearInput.data(yearData);
            
            var gridMenu=[{key: 'view', value: '查看'},{key: 'contract', value: '联系人信息'}];
            function ifExist(){
            	var flag=false;
            	for(var i=0;i<pointsData.length;i++){
            		a=(pointsData[i]=="modifyBenchValue");
                	if(pointsData[i]=="modifyBenchValue"){
                		if(gridMenu.length<3)
                    		gridMenu.push({key: 'edit', value: '修改标杆值'});
                    	flag=true;
                    }
                }
            	return flag;
            }
            
             grid.once("rowcontextmenu",function(data){
            	ifExist();
           	  	var m=tui.ctrl.menu(gridMenu);
           	  	var item=grid.activeItem();
               	m.show({x: data.event.clientX, y: data.event.clientY}, "rT");
               	m.on("select",function(data){
               		var checked=data.item.key;
               		if(checked==="view"){
               			ViewValue(item);
               		}
               		if(checked==="edit"){
               			editValue(item);
               		}
 					if(checked==="contract"){
 						if(item[18]){
							getUserInfo(item[18]);
						}else{
							tui.infobox("此条目无联系人信息","无联系人");
						}
               		}
               	});
               	return tui.cancelDefault(data.event);
              });
             
             grid.on("rowdblclick",function(data){
             	var item=grid.activeItem();
             	ViewValue(item);
             });
           // 查看标杆值
           function ViewValue(item){
        	   var dlg = tui.ctrl.dialog();
	           	var textarea;
	           	var textremark;
	           	dlg.on("open",function(){
	           		tui.ctrl.input("diaSectionSelect").value(item[16]);
	           		tui.ctrl.input("diaKpiSelect").value(item[15]);
	           		tui.ctrl.input("diaComSelect").value(item[17]);
	           		tui.ctrl.input("diaDateSelect").value(item[6]);
	           		textarea=tui.ctrl.input("diaValueInput");
	           		textarea.value(item[9]);
	           		textarea.readonly(true);
	           		textremark=tui.ctrl.input("diaValueRemark");
	           		textremark.value(item[24]);
	           		textremark.readonly(true);
	           	});
               dlg.showResource("editValueHtml","查看标杆值",
                   [
                      {name:"取消", func: function(){
                          dlg.close();
                      }},
                	]); 
           }
          //修改标杆值
            function editValue(item){
            	var dlg = tui.ctrl.dialog();
            	var textarea;
            	var textremark;
            	dlg.on("open",function(){
            		tui.ctrl.input("diaSectionSelect").value(item[16]);
	           		tui.ctrl.input("diaKpiSelect").value(item[15]);
	           		tui.ctrl.input("diaComSelect").value(item[17]);
	           		tui.ctrl.input("diaDateSelect").value(item[6]);
            		textarea=tui.ctrl.input("diaValueInput");
            		textarea.value(item[9]);
            		textremark=tui.ctrl.input("diaValueRemark");
            		//textremark.value(item[24]);
            	});
                dlg.showResource("editValueHtml","编辑标杆值",
                    [
                       {name:"保存", func: function(){
                    	   var fm=tui.ctrl.form();
                    	   if (item[9]==textarea.value()&&item[24]==textremark.value()){
                           	   dlg.close();
                    	   }else{
                    		   fm.id("modifyValueForm");
                           	   fm.action("${root}/api/modifyValue.do");
                           	   var userid,username;
                    		   if(item[18]==""){
                    			   userid='${session.get("uid")}';
                    			   username='${session.get("name")}';
                    		   }else{
                    			   userid=item[18];
                    			   username=item[22];
                    		   }
                           	   fm.immediateValue({
                           		   id:item[2],value:textarea.value(),remark:textremark.value(),
                           		   history:{
                           			   FieldCode:item[5],ReportDate:item[3],ComCode:item[4],CompName:item[17],FieldName:item[15],FieldUnit:item[19],BuzBoardCode:item[20], BestValue:item[23], ReportYear:item[6],
                           			initBenchMarkValue:item[9],BenchMarkValue:textarea.value(),initRemark:item[24], Remark:textremark.value(),init_userId:item[18],user_id:userid,UpdateUser:username,initUpdateTime:item[21]
                           		   }
                           	   });
                           	   fm.submit();
                    	   }
                       	   fm.submitForm("queryValueForm");
                    	   var proc = function() {
                               dlg.close();
                               fm.off("success", proc);
                           };
                           fm.once("success",proc);
                           
                       }},
                       {name:"取消", func: function(){
                           dlg.close();
                       }},
                 	]); 
            };
            tui.ctrl.paginator("pageBtn").on("change",function(){
            	queryForm.submit();
            });
            
            tui.ctrl.button("viewHistoryBtn").on("click",function(){
            	var dlg=tui.ctrl.dialog();
            	dlg.on("open",function(data){
            		var secData=tui.ctrl.input("sectionData");
            		
            		var yearInput=tui.ctrl.input("yearSelect1");
                	yearInput.data(yearData);
            		var secInput=tui.ctrl.input("sectionSelect1");
            		secInput.data(secData.data());
            		var kfm1=tui.ctrl.form("getKpiForm");
            		var cfm1=tui.ctrl.form("getComForm");
            		secInput.on("select",function(data){
                    	kfm1.immediateValue({sectionId:data.item.key});
                    	tui.ctrl.input("kpiSelect1").value(null);
                    	kfm1.submit();
                    	
                    	cfm1.immediateValue({sectionId:data.item.key});
                    	tui.ctrl.input("comSelect1").value(null);
                    	cfm1.submit();
                    });
            		 kfm1.on("receive",function(data){
           	       		tui.ctrl.input("kpiSelect1").data(data);
           	        });	
            	        
           	        cfm1.on("receive",function(data){
           	        	tui.ctrl.input("comSelect1").data(data);
           	        });	
            		tui.ctrl.input("kpiSelect1").data();
            		tui.ctrl.input("comSelect1").data();
            		var fm=tui.ctrl.form("getAnalysisHistoryForm");
            		
                	tui.ctrl.formAgent("sectionsAgent1").on("getvalue",function(data){
                		var sec=secData.data()._data;
                		var arr=[];
                		for(var i=0;i<sec.length;i++){
                			arr.push(sec[i].key);
                		}
                		data.value=arr;
                	});
                	tui.ctrl.button("diarunBtn").on("click",function(){
                		fm.submit();
                	});
            		fm.submit();
            		var grid1=tui.ctrl.grid("historyGrid");
            		fm.on("receive", function(data){
                   		tui.ctrl.paginator("pageBtn1").totalSize(data.length);
                   		grid1.data(data);
                   	});
            		 tui.ctrl.paginator("pageBtn1").on("change",function(){
            			 fm.submit();
                     });
                     
            		grid1.columns([
                         { name: '机构', key: 'CompName',sort: true },
                         { name: '指标', key: 'FieldName' ,sort: true},
                         { name: '年份', key: 'ReportYear',sort: true },
                         { name: '年度最优业务值', key: 'BestValue',width:99 },
                         { name: '标杆值', key: 'BenchmarkValue' },
                         { name: '单位', key: 'FieldUnit' },
                         { name: '最后编辑人', key: 'UpdateUser'},
                         { name: '备注', key: 'Remark'},
                         {name: '最后编辑时间', key: 'UpdateTime',sort: true,format:function(data){
                        	 if(data.rowIndex<0){return;}
                        	 data.cell.firstChild.innerHTML ="" ;
                        	 if(data.value)
                        	 	data.cell.firstChild.innerHTML =data.value.substr(0,10);
                         }}
                       ]);
            		
            		function ViewValue1(item){
                 	   var dlg = tui.ctrl.dialog();
         	           	var textarea;
         	           	var textremark;
         	           	dlg.on("open",function(){
         	           		$("#sectr").css("display","none");
         	           		//tui.ctrl.input("diaSectionSelect").value(item[25]);
         	           		tui.ctrl.input("diaKpiSelect").value(item[21]);
         	           		tui.ctrl.input("diaComSelect").value(item[20]);
         	           		tui.ctrl.input("diaDateSelect").value(item[6]);
         	           		textarea=tui.ctrl.input("diaValueInput");
         	           		textarea.value(item[9]);
         	           		textarea.readonly(true);
         	           		textremark=tui.ctrl.input("diaValueRemark");
         	           		textremark.value(item[10]);
         	           		textremark.readonly(true);
         	           	});
                        dlg.showResource("editValueHtml","查看标杆值",
                            [
                               {name:"取消", func: function(){
                                   dlg.close();
                               }},
                         	]); 
                    }
            		var menu=[{key: 'view', value: '查看'},{key: 'contract', value: '联系人信息'}];
            		grid1.once("rowcontextmenu",function(data){
                  	  	var m=tui.ctrl.menu(menu);
                  	  	var item=grid1.activeItem();
                      	m.show({x: data.event.clientX, y: data.event.clientY}, "rT");
                      	m.on("select",function(data){
                      		var checked=data.item.key;
                      		if(checked==="view"){
                       			ViewValue1(item);
                       		}
        					if(checked==="contract"){
        						if(item[19]){
        							getUserInfo(item[19]);
        						}else{
        							tui.infobox("此条目无联系人信息","无联系人");
        						}
       						}
                      	});
                      	return tui.cancelDefault(data.event);
                     });
            	});
            	dlg.showResource("viewHistoryHtml","查看历史记录",[
                    {name:"取消", func: function(){
                        dlg.close();
                    }},
              	])
            });
            //queryForm.submit();
        });

    </script>
    <!-- dialog Content -->
   <!--  <script id="editValueHtml" type="text/html">
		<div style="padding:0 20px">
			<table border="0" colspacing="0" colspading="0">
				<tr>
					<td>标杆值：</td>
					<td><span id="diaValueInput" class="tui-input" data-validator= "{'*any':'请填写标杆值'}" data-form="modifyValueForm"></span>
					</td>
				</tr>
				<tr>
					<td style="vertical-align: top; padding-top: 10px;">备注：</td>
					<td><span id="diaValueRemark" class="tui-textarea" data-validator= "{'*any':'请填写备注'}" data-form="modifyValueForm"></span>
					</td>			
				</tr>
			</table>
		</div>
    </script>
     -->
    <script id="editValueHtml" type="text/html">
		<div style="padding:0 20px;width:400px;text-align:center">
			<table border="0" colspacing="0" colspading="0" align="center">
				<tr id="sectr">
					<td>板块：</td>
					<td><span id="diaSectionSelect" data-readonly="true" class="tui-input select-input"></span>
					</td>
				</tr>
				<tr>
					<td>指标：</td>
					<td><span id="diaKpiSelect" data-readonly="true" class="tui-input select-input"></span>
					</td>
				</tr>
				<tr>
					<td>机构：</td>
					<td><span id="diaComSelect" data-readonly="true" class="tui-input select-input"></span>
					</td>
				</tr>
				<tr>
					<td>年份：</td>
					<td><span id="diaDateSelect" data-readonly="true" class="tui-input select-input" ></span>
					</td>
				</tr>
				<tr>
					<td>标杆值：</td>
					<td><span id="diaValueInput" class="tui-input select-input" data-validator= "{'*any':'请填写标杆值'}" data-form="modifyValueForm"></span>
					</td>
				</tr>
				<tr>
					<td style="vertical-align: top; padding-top: 10px;">备注：</td>
					<td><span id="diaValueRemark" class="tui-textarea select-input" data-validator= "{'*any':'请填写备注'}" data-form="modifyValueForm"></span>
					</td>
				</tr>
			</table>
		</div>
    </script>
    <script id="viewHistoryHtml" type="text/html" >
		<div style="padding:0 20px;width:1090px">
			<div style="margin-bottom:5px">
           		 板块：<span id="sectionSelect1" class="tui-input"  data-placeholder="选择板块" data-type="select" data-clearable="true"></span>
     	   		 指标：<span id="kpiSelect1" class="tui-input"  data-placeholder="选择指标" data-type="multi-select"></span>
           	 	年份：<span id="yearSelect1" class="tui-input"  data-placeholder="选择时间" data-type="select"></span>
           	 	机构：<span id="comSelect1" class="tui-input"  data-placeholder="选择机构" data-type="multi-select"></span>
				<span id="diarunBtn" class="tui-button">运行</span>
			</div>
			<div id="historyGrid" class="tui-grid"
          		data-resizable="true"
          		data-rowselectable="true"
          		style="width:100%;height:450px;"></div>
        	<div style="clear:both;margin-bottom:10px"></div>
        	<div id="pageBtn1" class="tui-paginator" style="float:right"  data-page-size="10" data-max-buttons="5" data-target="getAnalysisHistoryForm"></div>
		</div>
		<span id="getAnalysisHistoryForm" class="tui-form" data-action="${root}/api/queryHistory.do" data-waiting="正在加载,请稍后..." >
			<span data-field="sectionId" data-target="sectionSelect1"></span>
			<span id="sectionsAgent1" data-field="sections"></span>
			<span data-field="yearTime" data-target="yearSelect1"></span>
			<span data-field="KPIs" data-target="kpiSelect1"></span>
			<span data-field="companyId" data-target="comSelect1"></span>
			<span data-field="page" data-target="pageBtn1" ></span>
		</span>
    </script>
</head>
<body>
   <%@include file="../main-common-include.jspf"%>
   <%@include file="../common-header.jspf"%>
    <!---左侧筛选栏--->
    <div class="contDiv">
    	<p class="left-div-title">标杆调整筛选</p>
        <div>
            板块：<span id="sectionSelect" class="tui-input"  data-placeholder="选择板块" data-type="select" data-clearable="true"></span>
        </div>
        <div>
            指标：<span id="kpiSelect" class="tui-input"  data-placeholder="选择指标" data-type="multi-select"></span>
        </div>
        <div>
            时间：<span id="yearSelect" class="tui-input"  data-placeholder="选择时间" data-type="select"></span>
        </div>
        <div>
            机构：<span id="comSelect" class="tui-input"  data-placeholder="选择机构" data-type="multi-select"></span>
        </div>
        <a id="runBtn" class="tui-button run-btn">运行</a>
    </div>
    <div class="left-div left-body"></div>

    <!---右侧--->
    <div class="right-body">
    	<a id="viewHistoryBtn" class="tui-button tui-primary" style="float:right">查看历史记录</a>
        <div style="clear:both;margin-bottom:10px"></div>
        <div id="valueGrid" class="tui-grid"
          data-resizable="true"
          data-rowselectable="true"
          style="width:100%;height:510px;"></div>
        <div style="clear:both;margin-bottom:10px"></div>
        <div id="pageBtn" class="tui-paginator" style="float:right" data-total-size="100" data-page-size="10" data-max-buttons="5"></div>
    </div>
</body>
<span id="queryValueForm" class="tui-form" data-action="${root}/api/queryValue.do" data-waiting="正在加载,请稍后..." data-target="valueGrid">
	<span data-field="sectionId" data-target="sectionSelect"></span>
	<span id="sectionsAgent" data-field="sections" data-target="sectionData" ></span>
	<span data-field="yearTime" data-target="yearSelect"></span>
	<span data-field="KPIs" data-target="kpiSelect"></span>
	<span data-field="companyId" data-target="comSelect"></span>
	<span data-field="page" data-target="pageBtn" ></span>
</span>
</html>

